package cn.billho.popcache.core.glock;

public class LuaScript {
    public static final String LOCK_SCRIPT =
            "local lock_key = KEYS[1]\n" +
            "local lock_value = ARGV[1]\n" +
            "local lock_timeout = tonumber(ARGV[2])\n" +
            " \n" +
            "local result = redis.call('SET', lock_key, lock_value, 'NX', 'EX', lock_timeout) \n" +
            "if result then \n" +
            "    return 1 \n" +
            "else\n" +
            "    return 0 \n" +
            "end";
    public static final String RELEASE_LOCK_SCRIPT =
            "local lock_key = KEYS[1]\n" +
            "local lock_value = ARGV[1]\n" +
            " \n" +
            "if redis.call('GET', lock_key) == lock_value then\n" +
            "    redis.call('DEL', lock_key)\n" +
            "    return 1  \n" +
            "else\n" +
            "    return 0  \n" +
            "end";

}